package 数据结构.单调栈;

import java.util.Stack;

/**
 * @description:
 * @author: ywk
 * @date: 2020-12-28
 */
public class 更高的温度 {
    public static int[] dailryTemperature(int[] nums) {
        int[] arr = new int[nums.length];
        Stack<Integer> stack = new Stack();
        for (int i = nums.length - 1; i >= 0; i--) {
            while (!stack.isEmpty() && nums[stack.peek()] <= nums[i]) {
                stack.pop();
            }
            arr[i] = stack.empty() ? -1 : stack.peek() - i;
            stack.push(i);
        }
        return arr;
    }

    public static void main(String[] args) {
        System.out.println(dailryTemperature(new int[]{2, 1, 2, 4, 3}));
    }
}
